from utils.utils import *
import allure
from faker import Faker
faker = Faker(locale='zh_CN')
name=faker.name()

@allure.story("添加标签")
def test_add_tag():
    reset_token()

    # 创建请求步骤
    add_tag = send_requests(
        "新增标签",
        "post",
        "/adminapi/user/user_label/save.html",
        {'label_cate': 2, 'label_name': name }  # 使用 name 变量
    ). \
    validate().\
    assert_equal("status_code", 200).\
    assert_equal('headers."Content-Type"', "application/json; charset=utf-8").\
    assert_equal("body.status", 200).\
    assert_equal("body.msg", "保存成功").\
    assert_equal("body.code", "100000")

    # 执行请求
    add_tag_step = step_obj(add_tag)
    res = get_last_response([add_tag_step])


@allure.story("删除标签")
def test_del_tag():
    reset_token()
    get_tag = send_requests(
        '查询标签',
        'get',
        '/adminapi/user/user_label?page=1&limit=15&label_cate=2'). \
    validate().\
    assert_equal("status_code", 200).\
    assert_equal('headers."Content-Type"', "application/json; charset=utf-8").\
    assert_equal("body.status", 200).\
    assert_equal("body.msg", "success")

    get_tag_step = step_obj(get_tag)
    res = get_last_response([get_tag_step, ])

    for i in res['res_body']['data']['list']:
        if i['label_name'] == name:
            id = i['id']
            print(id)
    #删除
    delete_tag = send_requests(
        "删除标签",
        'delete',
        f"/adminapi/user/user_label/del/{id}"
    ). \
    validate().\
    assert_equal("status_code", 200).\
    assert_equal('headers."Content-Type"', "application/json; charset=utf-8").\
    assert_equal("body.status", 200).\
    assert_equal("body.msg", "删除成功").\
    assert_equal("body.code", "100002")
    delete_tag_step = step_obj(delete_tag)
    res = get_last_response([delete_tag_step,])







